package com.gxa.order.controller;

import com.gxa.common.commons.JsonResult;
import com.gxa.common.commons.R;
import com.gxa.common.utils.FileUtils;
import com.gxa.order.pojo.HotelOrder;
import com.gxa.order.pojo.hotel.HotelOrderTenant;
import com.gxa.order.pojo.hotel.Tenant;
import com.gxa.order.service.HotelOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

@RestController
@RequestMapping("/hotel_order")
public class HotelOrderController {
    @Autowired
    private HotelOrderService hotelOrderService;

    /**住宿订单查询
     *
     * @param map
     * @return
     */
    @PostMapping("/findorder")
    public JsonResult findHotelOrderList(@RequestBody Map map){
        return hotelOrderService.findHotelOrderList(map);
    }

    /**
     * 查看住宿订单详情
     * @param id
     * @return
     */
    @PostMapping("/findorder_id")
    public JsonResult findHotelOrder(Integer id){
        return hotelOrderService.findHotelOrder(id);
    }

    /**
     * 住宿订单类型数量
     * @param statu
     * @return
     */
    @PostMapping("/count")
    public JsonResult count(Integer statu){
        return hotelOrderService.countHotelOrderStatu(statu);
    }

    /**
     * 删除住宿订单
     * @param id
     * @return
     */
    @PostMapping("/Delorder_id")
    public R delHotelOrder(Integer id){
        return hotelOrderService.delHotelOrder(id);
    }

    /**
     * 修改支付状态（支付时间和支付方式）
     * @param payTime
     * @param payType
     * @param statu
     * @param id
     * @return
     */
    @PostMapping("/updataorder")
    public R updateHotelOrder(String payTime, Integer payType, Integer statu,Integer id){
        return hotelOrderService.updateHotelOrder(payTime,payType,statu,id);
    }

    /**
     * 增加住宿订单
     * @param hotelOrderTenant
     * @return
     */
    @PostMapping ("/addorder")
    public R addHotelOrder(@RequestBody HotelOrderTenant hotelOrderTenant){
        return hotelOrderService.addHotelOrder(hotelOrderTenant);
    }

    /**
     * 上传护照照片
     * @param file
     * @param request
     * @return
     */
    @PostMapping("/passport")
    public R fileUpload(MultipartFile file, HttpServletRequest request){
        String s = FileUtils.fileUpload("/load", file, request);
        R r =new R();
        if(s !=null&&s!=""){
            r.setCode(200);
            r.setMsg("上传图片成功");
            r.setData(s);
        }else {
            r.setCode(500);
            r.setMsg("上传失败");
        }
        return r;
    }

    /**
     * 修改住宿订单状态
     * @param statu
     * @param id
     * @return
     */
    @GetMapping("/updatestatu")
    public R updatestatu(@RequestParam("statu") Integer statu,@RequestParam("id") Integer id){
        return hotelOrderService.updateHotelOrderstatu(statu,id);
    }

    /**
     * 修改订单房间号
     * @param id
     * @param room_number
     * @return
     */
    @GetMapping("/updateroom")
    public R updateRoom(@RequestParam("id") Integer id,@RequestParam("roomId") Integer roomId,@RequestParam("room_number")String room_number){
        return hotelOrderService.updateHotelOrderRoom(id,roomId,room_number);
    }

    /**
     * 根据订单编号查看订单id
     * @param orderNumber
     * @return
     */
    @PostMapping("/findOrderId")
    public R findid(String orderNumber){
        return hotelOrderService.findOrderid(orderNumber);
    }

    /**
     * 根据订单id查看状态
     * @param id
     * @return
     */
    @PostMapping("/findOrderStatu")
    public R findOrderStatu(Integer id){
        return hotelOrderService.findOrderStatu(id);
    }
}
